# -*- coding: utf-8 -*-
# @Time : 2021/7/2 23:31
# @Author : feimaotuiya
# @File : page_ecshop_front_cat_goods_details.py
# @Project : ecshop-gitee
import time

from selenium.webdriver.common.by import By

from utils.java_script_exec import JavaScriptExec


class PageEcshopFrontCatGoodsDetails():
    # 查看商品详情
    def __init__(self, driver):
        self.driver = driver
        # 元素定位
        self.loc_front_cat_goods_details = (By.XPATH, '//form[@id="compareForm"]/div/div[1]/a/img')
        self.loc_front_cat_secondary_goods_details_xpath = (
        By.XPATH, '/html/body/div[7]/div[2]/div[3]/div/form/div/div[8]/p/a')
        self.loc_add_remark_textarea = (By.XPATH, '//*[@id="commentForm"]/table/tbody/tr[4]/td[2]/textarea')
        self.loc_front_add_remark_submint = (By.XPATH, '//form[@id="commentForm"]/table/tbody/tr[5]/td/input')
        self.loc_front_login_assert = (By.XPATH, '//font[@id="ECS_MEMBERZONE"]/a[1]')  # 断言

    # 搜索查看
    def front_cat_goods_details_xpath(self):
        self.driver.find_element(*self.loc_front_cat_goods_details).click()

    # 断言
    def ront_cat_goods_details_assert(self):
        actual = self.driver.find_element(*self.loc_front_login_assert).text
        return actual

    # 二级分类查看详情
    def front_cat_secondary_goods_details_xpath(self):
        self.driver.find_element(*self.loc_front_cat_secondary_goods_details_xpath).click()

    # 滚动页面
    def front_add_remark_scroll(self):
        JavaScriptExec(self.driver).js_scroll()

    # 输入评论内容
    def front_add_remark_textarea(self, remark):
        self.driver.find_element(*self.loc_add_remark_textarea).send_keys(remark)

    # 点击提交
    def front_add_remark_submint(self):
        self.driver.find_element(*self.loc_front_add_remark_submint).click()
        time.sleep(1)
        actual = self.driver.switch_to.alert.text
        return actual

    # 查看商品详情
    def cat_goods_details(self):
        self.front_cat_goods_details_xpath()
        actual = self.ront_cat_goods_details_assert()
        return actual

    # 添加评论
    def add_remark(self, remark):
        self.front_add_remark_scroll()
        self.front_add_remark_textarea(remark)
        actual = self.front_add_remark_submint()
        return actual
